import os

from config import conf

_id2label = None


def get_id2label():
    global _id2label
    if _id2label is None:
        classes = open(conf.class_path, 'r').read().split()
        _id2label = {i: label for i, label in enumerate(classes)}
        print(f'load id2label:{_id2label}')
    return _id2label


def ensure_pdir_exist(path):
    print(f'检查路径:{path}')
    parent_dir = os.path.dirname(path)
    if not os.path.exists(parent_dir):
        print(f'父目录不存在，创建目录:{parent_dir}')
        os.makedirs(parent_dir, exist_ok=True)
    else:
        print(f'父目录已存在:{parent_dir}')


def _test_ensure():
    path = './data/rf2/test.txt'
    ensure_pdir_exist(path)


if __name__ == '__main__':
    _test_ensure()
